<template>
	<view class="comments">
		<!-- <view class="h">
			<view :class="showType == 0 ? 'active item' : 'item'" @click="switchTab">
				<view class="txt">全部({{allCount}})</view>
			</view>
			<view :class="showType == 0 ? 'item' : 'active item'" @click="switchTab">
				<view class="txt">有图({{hasPicCount}})</view>
			</view>
		</view> -->
		<view class="b">
			<view class="item" v-for="(item, index) of comments" :key="item.id" :data-index="index">
				<view class="info">
					<view class="user">
						<image :src="item.baseUrl+item.imgUrl" />
						<text>{{item.nickname}}</text>
					</view>
					<view class="time">{{item.createdStamp}}</view>
				</view>
				<view class="comment">{{item.content}}</view>
				<view class="imgs" v-if="item.productReviewContent">
					<image class="img" v-for="(iitem, iindex) of item.productReviewImages" :key="iitem.productReviewImageId" :src="item.baseUrl+iitem.original" :data-index="iindex" />
				</view>
<!-- 				<view class="spec">
					<text class="item">白色 2件</text>
				</view> -->
				<!-- <view class="customer-service" v-if="item.commentReplyVO">
					<text class="u">卖家回复：</text>
					<text class="c">{{item.commentReplyVO.replyContent}}</text>
				</view> -->
			</view>
		</view>
	</view>
</template>

<script>
	import {getProductReview} from '@/api/mall/product'
	import {
		getUrl
	} from '@/common/oss';
	
	export default {
		data() {
			return {
				comments: [],
				allCommentList: [],
				picCommentList: [],
				typeId: 0,
				valueId: 0,
				showType: 0,
				allCount: 0,
				hasPicCount: 0,
				allPage: 1,
				picPage: 1,
				page: 1,
				size: 20
			}
		},
		onLoad: function(e) {
			var productId = e.valueId;
			this.getComments(productId)
		},
		onUnload: function() {
			this.page = 1;
			this.comments = [];
		},
		methods: {
			//获得 评论数量
			getProductReviewCount() {
				
			},
			//获得 评论详情
			getComments(productId) {
				getProductReview(this.getParameters(productId)).then(response => {
					
					
					if (response.total > 0 && response.data.length > 0) {
						console.log("comments ...");
						console.log("comments:" + JSON.stringify(response.data));
						for (var i = 0; i < response.data.length; i++) {
							response.data[i].baseUrl = getUrl();
						}
						this.comments = this.comments.concat(response.data);
						
						console.log("comments:" + JSON.stringify(this.comments));
						this.page++;
					}
				});
			},
			getParameters(productId) {
				let query = {};
				query.productId = productId;
				query.page = this.page;
				query.limit = 20;
				query.orderBy = "createdStamp";
				query.sort = "desc";
				return query;
				
			},
			switchTab () {
				this.showType = this.showType === 1 ? 0 : 1;
				this.getCommentList();
			}
		}
	}
</script>

<style>
	.comments {
		width: 720upx;
		height: auto;
		padding-left: 30upx;
		background: #fff;
		margin: 20upx 0;
	}

	.comments .h {
		position: fixed;
		left: 0;
		top: 0;
		z-index: 1000;
		width: 100%;
		display: flex;
		background: #fff;
		height: 84upx;
		border-bottom: 1px solid rgba(0, 0, 0, .15);
	}

	.comments .h .item {
		display: inline-block;
		height: 82upx;
		width: 50%;
		padding: 0 15upx;
		text-align: center;
	}

	.comments .h .item .txt {
		display: inline-block;
		height: 82upx;
		padding: 0 20upx;
		line-height: 82upx;
		color: #333;
		font-size: 30upx;
		width: 170upx;
	}

	.comments .h .item.active .txt {
		color: #ab2b2b;
		border-bottom: 4upx solid #ab2b2b;
	}

	.comments .b {
		/* margin-top: 85upx; */
		height: auto;
		width: 720upx;
	}

	.comments .b.no-h {
		margin-top: 0;
	}

	.comments .item {
		height: auto;
		width: 720upx;
		overflow: hidden;
		border-bottom: 1px solid #d9d9d9;
		padding-bottom: 10upx;
	}

	.comments .info {
		height: 127upx;
		width: 100%;
		padding: 33upx 0 27upx 0;
	}

	.comments .user {
		float: left;
		width: auto;
		height: 67upx;
		line-height: 67upx;
		font-size: 0;
	}

	.comments .user image {
		float: left;
		width: 67upx;
		height: 67upx;
		margin-right: 17upx;
		border-radius: 50%;
	}

	.comments .user text {
		display: inline-block;
		width: auto;
		height: 66upx;
		overflow: hidden;
		font-size: 29upx;
		line-height: 66upx;
	}

	.comments .time {
		display: block;
		float: right;
		width: auto;
		height: 67upx;
		line-height: 67upx;
		color: #7f7f7f;
		font-size: 25upx;
		margin-right: 30upx;
	}

	.comments .comment {
		width: 720upx;
		padding-right: 30upx;
		line-height: 45.8upx;
		font-size: 29upx;
		margin-bottom: 16upx;
	}

	.comments .imgs {
		width: 720upx;
		height: 150upx;
		margin-bottom: 25upx;
	}

	.comments .imgs .img {
		height: 150upx;
		width: 150upx;
		margin-right: 28upx;
	}

	.comments .spec {
		width: 720upx;
		height: 25upx;
		font-size: 24upx;
		color: #999;
	}

	.comments .spec .item {
		color: #7f7f7f;
		font-size: 25upx;
	}

	.comments .customer-service {
		width: 690upx;
		height: auto;
		overflow: hidden;
		margin-top: 40upx;
		background: rgba(0, 0, 0, .03);
		padding: 21upx;
	}

	.comments .customer-service .u {
		font-size: 24upx;
		color: #333;
		line-height: 37.5upx;
	}

	.comments .customer-service .c {
		font-size: 24upx;
		color: #999;
		line-height: 37.5upx;
	}
</style>
